import requests
from ..util.log_util import logger


class Base:
    def __init__(self):
        self.url = "https://litemall.hogwarts.ceshiren.com"
        self.headers = {
            'x-litemall-admin-token': self.token()
        }

    def token(self):
        url = 'https://litemall.hogwarts.ceshiren.com/admin/auth/login'
        data_json = {
          "username": "hogwarts",
          "password": "test12345",
          "code": ""
        }
        token = requests.post(url=url, json=data_json).json()["data"]["token"]
        logger.debug(f'获取了token:"{token}"')
        return token

    def send(self, method, url, **kwargs):
        logger.debug(f'请求"{method}",url"{url}",**kwargs"{kwargs}"')
        return requests.request(method, url, **kwargs)
